package com.iotek.ssm.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CustomDateConverter implements Converter<String, Date> {
    public Date convert(String source) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            if (source.length() < 12)
                return simpleDateFormat.parse(source);
            else
                return simpleDateFormat1.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
